package hunterxhunter.greedisland.gui;

import hunterxhunter.greedisland.data.enums.NenType;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author Markus Schr&ouml;der
 */
public class Dialog {

    public static String askNickname(JFrame parent) {
        
        boolean showUsernameRegex = false;
        boolean showUsernameAlreadyExists = false;
        boolean playernameOK = false;
        String playername;
        do {
            playername = JOptionPane.showInputDialog(parent, 
                    "Nickname?" + 
                    (showUsernameRegex ? "\nGreed Island supports only nicknames with letters..." : "") + 
                    (showUsernameAlreadyExists ? "\n..." : ""), 
                    "Here is a ring for you", JOptionPane.QUESTION_MESSAGE);
            
            if(playername == null)
                break;
            
            showUsernameAlreadyExists = false;
            showUsernameRegex = false;
            
            if(playername.matches("[a-zA-Z]+")) {
                playernameOK = true;
            } else {
                showUsernameRegex = true;
            }
            
        } while(!playernameOK);
        
        if(playernameOK) {
            return playername;
        }
        
        return null;
    }
    
    public static NenType askNenType(JFrame parent) {
        NenSelectionDialog nsd = new NenSelectionDialog(parent, true);
        nsd.setLocationRelativeTo(null);
        nsd.setVisible(true);
        return nsd.getNenType();
    }
    
}
